package cn.usian.controller;

import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("emp")
@CrossOrigin
public class EmpController {
    @Resource
    private EmpService empService;

    @RequestMapping("findPage")
    public Page<Emp>findPage(String searchMap,Integer pageNum){
        Page<Emp> empPage = new Page<>(pageNum, 3);
        Page<Emp> page = empService.findPage(searchMap, empPage);
        return page;
    }
    @RequestMapping("findAll")
    public List<Emp>findAll(String searchMap){
        return empService.findAll(searchMap);
    }
    @RequestMapping("add")
    public void add(@RequestBody Emp emp){
        empService.add(emp);
    }

    @RequestMapping("update")
    public void update(@RequestBody Emp emp){
        empService.update(emp);
    }
    @RequestMapping("delete")
    public void delete(Integer eid){
        empService.delete(eid);
    }
    @RequestMapping("findByEid")
    public Emp findByEid(Integer eid){
       return empService.findByEid(eid);
    }
}
